package com.newcoin.chat.controller;

import com.newcoin.chat.beans.vo.ResultVo;
import com.newcoin.chat.beans.vo.UserVo;
import com.newcoin.chat.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping(value = "/user")
public class UserController {

    @Autowired
    private UserService service;

    /**
     * 是否授权
     *
     * @param superUserId
     * @return
     */
    @GetMapping(value = "/whetherAuthorized")
    public ResultVo<UserVo> whetherAuthorized(@RequestParam long superUserId) {
        try {
            return service.whetherAuthorized(superUserId);
        } catch (Exception e) {
            ResultVo<UserVo> resultVo = new ResultVo<>();
            resultVo.setStatus(500);
            resultVo.setMsg("系统出错");
            return resultVo;
        }
    }

    /**
     * 授权
     *
     * @param superUserId
     * @param mobile
     * @param nickname
     * @param headImgPath
     * @return
     */
    @PostMapping(value = "/authorized")
    public ResultVo<UserVo> authorized(long superUserId, String mobile, String nickname, String headImgPath) {
        try {
            return service.authorized(superUserId, mobile, nickname, headImgPath);
        } catch (Exception e) {
            e.printStackTrace();
            ResultVo<UserVo> resultVo = new ResultVo<>();
            resultVo.setStatus(500);
            resultVo.setMsg("系统出错");
            return resultVo;
        }
    }

    /**
     * 通过Id获取用户信息
     *
     * @param userId
     * @return
     */
    @GetMapping(value = "/getUserInfoById")
    public ResultVo<UserVo> getUserInfoById(long userId) {
        try {
            return service.getUserInfoById(userId);
        } catch (Exception e) {
            ResultVo<UserVo> resultVo = new ResultVo<>();
            resultVo.setStatus(500);
            resultVo.setMsg("系统出错");
            return resultVo;
        }
    }

    /**
     * 修改头像
     *
     * @param userId
     * @param headPath
     * @return
     */
    @PostMapping(value = "/updateUserHead")
    public ResultVo updateUserHead(Long userId, String headPath) {
        try {
            return service.updateUserHead(userId, headPath);
        } catch (Exception e) {
            ResultVo<UserVo> resultVo = new ResultVo<>();
            resultVo.setStatus(500);
            resultVo.setMsg("系统出错");
            return resultVo;
        }
    }

    /**
     * 修改昵称
     *
     * @param userId
     * @param nickname
     * @return
     */
    @PostMapping(value = "/updateUserNickname")
    public ResultVo updateUserNickname(Long userId, String nickname){
        try {
            return service.updateUserNickname(userId, nickname);
        } catch (Exception e) {
            ResultVo<UserVo> resultVo = new ResultVo<>();
            resultVo.setStatus(500);
            resultVo.setMsg("系统出错");
            return resultVo;
        }
    }

}
